'use strict';
var f2Controller = require('./f2.controller');
var f2View = require('./f2.view.html');
exports = module.exports = function ($scope, $rootScope, $timeout, $stateParams, $uibModal, yxtable14, $compile, $alert, $API, $go, $rule, throttleSubmit) {

// 规则类
    $scope.Rule = $rule;
// 基本属性
    $scope.fromObj = {
        api: {
            breadcrumb: '一级菜单,二级菜单,三级菜单',
            title: '开卡表单',
            detail: 'cardfrom',
            detailUrl: 'cardfromDetail',
            submit: 'cardfromEdit',
            submitUrl: 'cardfromEdit'
        },
        formColume: [
            {title:'username',name:'用户名',type:'输入框',mock:'名字',required:true,validate:'不可使用特殊符号',maxlength:50},
            {title:'account',name:'账号',type:'输入框',mock:'词语',required:true,validate:'不可使用中文以及特殊符号',maxlength:20},
            {title:'rote',name:'中奖概率',type:'输入框',mock:'数字',required:true,validate:'请输入0-100数字或保留两位小数',maxlength:10,bottomNote:true},
            {title:'money',name:'花费金钱',type:'输入框',mock:'数字',required:true,validate:'请输入0-100数字或保留两位小数',maxlength:10},
            {title:'price',name:'彩票单价',type:'输入框',mock:'数字',required:true,validate:'请输入0-100整数',maxlength:10},
            {title:'lotteryType',name:'彩票类型',type:'下拉框',mock:'',required:true,dropName:'lotteryList',dropApi:'lotteryListApi'},
            {title:'lotteryType2',name:'彩票类型2',type:'下拉框',mock:'',required:true,dropName:'lotteryList2',option:`{'0':'啦啦','1':'嘎嘎','2':'嗯嗯'}`},
            {title:'note',name:'获奖感言',type:'文本域',mock:'词语',required:false,maxlength:62},
            {title:'isotherget',name:'他人代领',type:'假开关',mock:'枚举2',required:true},
            {title:'ismeget',name:'自己领奖',type:'开关',mock:'枚举2',required:true},
            {title:'gettype',name:'领奖方式',type:'单选',mock:'枚举3',required:true,option:`{'0':'步行','1':'骑车','2':'开车'}`},
            {title:'donatewho',name:'捐献对象',type:'复选',mock:'枚举3',required:true,option:`{'0':'红十字美美会','1':'贪官户头','2':'壹基金'}`,bottomNote:true},
            {title:'borrowwho',name:'借给亲戚',type:'枚举填写',mock:'文本数组',required:true},
            {title:'borrowwhoswho',name:'借给亲戚的亲戚',type:'弹框处理',mock:'对象数组',required:true},
        ]
    };
// 增删元素
    $scope.addItem = function(objName) {
        $scope.fromObj[objName].push({})
    };
    $scope.removeItem = function(objName, index) {
        $scope.fromObj[objName].splice(index, 1)
    };
// 生成代码
    var templateF = ''; // 表单HTML代码预生产变量
    var templateJ = ''; // 表单JS代码预生产变量
    var templateA =''; // 表单假数据预生产变量
    $scope.makeFormCodeAndReview = (function() {
        var json = $scope.fromObj;
        templateA += `
                                                                                                    $API = {}
                                                                                                    $API.Detail = {};
                                                                                                    $API.Drop = {};
                                                                                                    $API.Edit = {};
                                                                                                    var $ajax = {};
                                                                                                    $ajax.sent = function(param) {
                                                                                                        return new Promise(function(resolve, reject) {
                                                                                                            if(param.url == '${ json.api.detailUrl }') {
                                                                                                                var mock = {
                                                                                                                    'code': 200,
                                                                                                                    'msg':'',
                                                                                                                    'data': {
                                                                                                                    }
                                                                                                                };
                                                                                                                var Random = Mock.Random;
                                                                                                                mock.data = {`
        for(var i = 0, l = json.formColume.length; i < l; i++) {
            var one = json.formColume[i];
            var title = one.title;
            var mock = (one.mock || '').toLowerCase();
            if (mock.indexOf('日期') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.date('yyyy-MM-dd'),`
            } else if (mock.indexOf('名字') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.cname(),`
            } else if (mock.indexOf('词语') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.cparagraph(1),`
            } else if (mock.indexOf('id') > -1 || mock.indexOf('数字') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.natural(1, 10000),`
            } else if (mock.indexOf('网址') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.url(),`
            } else if (mock.indexOf('枚举2') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.integer(0, 1),`
            } else if (mock.indexOf('枚举3') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.integer(0, 2),`
            } else if (mock.indexOf('枚举4') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.integer(0, 3),`
            } else if (mock.indexOf('ip') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.ip(),`
            } else if (mock.indexOf('金钱') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.float(1, 10000, 2, 2),`
            } else if (mock.indexOf('邮箱') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.float(1, 10000, 2, 2),`
            } else if (mock.indexOf('地址') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.email(),`
            } else if (mock.indexOf('文本数组') > -1) {
                templateA += `
                                                                                                                    '${ title }': ['111', '222'],`
            } else if (mock.indexOf('对象数组') > -1) {
                templateA += `
                                                                                                                    '${ title }': [{"id":3,"name":"尹晶晶"},{"id":18,"name":"张士博"}],`
            } else if (mock.indexOf('文本') > -1) {
                templateA += `
                                                                                                                    '${ title }': Random.string('lower', 3, 10),`
            } else { // 其他
                templateA += `
                                                                                                                    '${ title }': '${ mock }',`
            }
        }
        templateA = templateA.replace(/,$/, '');
        templateA += `
                                                                                                                }
                                                                                                                resolve(mock);
                                                                                                                return false;
                                                                                                            }
                                                                                                            if(param.url == '${ json.api.submitUrl }') {
                                                                                                                var mock = {
                                                                                                                    'code': 200,
                                                                                                                    'msg':'',
                                                                                                                    'data': {
                                                                                                                        'res_code': 1,
                                                                                                                        'res': '保存成功了'
                                                                                                                    }
                                                                                                                };
                                                                                                                resolve(mock);
                                                                                                                return false;
                                                                                                            }`
        for(var i = 0, l = json.formColume.length; i < l; i++) {
            var one = json.formColume[i];
            var url = one.url;
            if(url) {
                templateA += `
                                                                                                            if(param.url == '${ url }') {
                                                                                                                var mock = {
                                                                                                                    'code': 200,
                                                                                                                    'msg':'',
                                                                                                                    'data': [
                                                                                                                        {'id': 11, 'name': '假数据1'},
                                                                                                                        {'id': 21, 'name': '假数据2'},
                                                                                                                        {'id': 31, 'name': '假数据3'},
                                                                                                                        {'id': 41, 'name': '假数据4'},
                                                                                                                        {'id': 51, 'name': '假数据5'},
                                                                                                                        {'id': 61, 'name': '假数据6'}
                                                                                                                    ]
                                                                                                                };
                                                                                                                resolve(mock);
                                                                                                                return false;
                                                                                                            }`
            }
        }
        templateA += `
                                                                                                        });
                                                                                                    };
                                                                                                    $API.Edit.${ json.api.submit } = function(opt) {
                                                                                                        return new Promise(function(resolve, reject){
                                                                                                            $ajax.sent({
                                                                                                                method: 'POST',
                                                                                                                url: '${ json.api.submitUrl }',
                                                                                                                params: opt // 传参
                                                                                                            }).then(function(res){
                                                                                                                resolve(res.data)
                                                                                                            });
                                                                                                        });
                                                                                                    };
                                                                                                    $API.Detail.${ json.api.detail } = function(opt) {
                                                                                                        return new Promise(function(resolve, reject){
                                                                                                            $ajax.sent({
                                                                                                                method: 'GET',
                                                                                                                url: '${ json.api.detailUrl }',
                                                                                                                params: opt // 传参
                                                                                                            }).then(function(res){
                                                                                                                resolve(res.data)
                                                                                                            });
                                                                                                        });
                                                                                                    };`
        for(var i = 0, l = json.formColume.length; i < l; i++) {
            var one = json.formColume[i];
            var title = one.title;
            var dropName = one.dropName;
            if(!dropName){ continue; }
            var dropApi = one.dropApi;
            var staticData = '';
            try{
                staticData = eval('('+ one.option +')');
            }catch(e) {
                alert('error1036::json格式有问题');
                console.error('json格式有问题', one.option, e);
            }
            templateA += `
                                                                                                    $API.Drop.${ dropName } = function(opt, params) {
                                                                                                        return new Promise(function(resolve, reject){
                                                                                                            var nosearch = opt.indexOf('nosearch') > -1`
            if(dropApi) {
                templateA += `
                                                                                                            var noall = opt.indexOf('noall') > -1
                                                                                                            var arr = noall ? [{id: 0, name:'全部${ title }'}] :[];
                                                                                                            $ajax.sent({
                                                                                                                method: 'GET',
                                                                                                                url: '${ dropApi }',
                                                                                                                params: params || {} // 传参
                                                                                                            }).then(function(res){
                                                                                                                resolve(select2Config( arr.concat(res.data||[]), !nosearch ))
                                                                                                            });`
            } else {
                templateA += `
                                                                                                            var noall = opt.indexOf('noall') > -1
                                                                                                            var arr = noall ? [{id: 0, name:'全部${ title }'}] :[];
                                                                                                            var arr2 = [`
                for(var ll in staticData) {
                    templateA += `
                                                                                                                {'id': ${ ll },'name':'${ staticData[ll] }' },`
                }
                templateA = templateA.replace(/,$/, '');
                templateA += `
                                                                                                            ];
                                                                                                            resolve(select2Config( arr.concat(arr2), 0 ))`
            }
            templateA += `
                                                                                                        });
                                                                                                    };`
        }
        eval(templateA);
        ///////////////////////////////////////////////////////////////////////////////
        templateJ += `
                                                                                                    $scope.Rule = $rule;
                                                                                                    $scope.frm = {
                                                                                                        'id': 0,`
        for(var i = 0, l = json.formColume.length; i < l; i++) {
            var one = json.formColume[i];
            var title = one.title;
            var name = one.name;
            var type = one.type;
            if(type == "枚举填写"){
                templateJ += `
                                                                                                        \/\/ 枚举表单项: ${ name }
                                                                                                        ${ title }: [],
                                                                                                        \/\/ 枚举参数1
                                                                                                        ${ title }Opt1: '',`
            } else if(type == "弹框处理"){
                templateJ += `
                                                                                                        \/\/ 弹框表单项: ${ name }
                                                                                                        ${ title }: [],`
            } else {
                templateJ += `
                                                                                                        \/\/ 表单项: ${ name }
                                                                                                        ${ title }: '',`
            }
        }
        templateJ = templateJ.replace(/,$/, '');
        templateJ += `
                                                                                                    }
                                                                                                    if( $stateParams.id ){
                                                                                                        $scope.frm.id = $stateParams.id;
                                                                                                        $API.Detail.${ json.api.detail }({id: $scope.frm.id})
                                                                                                        .then(function(data) {
                                                                                                            $timeout(function() {
                                                                                                                angular.extend($scope.frm, data)
                                                                                                            }, 0)
                                                                                                        });
                                                                                                    }
                                                                                                    $scope.frm2 = {`
        for(var i = 0, l = json.formColume.length; i < l; i++) {
            var one = json.formColume[i];
            var title = one.title;
            var name = one.name;
            var type = one.type;
            if(type == "下拉框" && one.dropName){
                templateJ += `
                                                                                                        \/\/ 数据源: ${ name }列表
                                                                                                        ${ title }List: select2Config( [] ),`
            } else if(type == "假开关"){
                templateJ += `
                                                                                                        \/\/ 响应式开关
                                                                                                        ${ title }Change: function(){
                                                                                                            $scope.frm.${ title } = ! $scope.frm.${ title } ? 1 : 0
                                                                                                        },`
            } else if(type == "枚举填写"){
                templateJ += `
                                                                                                        \/\/ 枚举项的增加
                                                                                                        ${ title }Add: function(){
                                                                                                            if(!$scope.frm.${ title }Opt1){
                                                                                                                return false
                                                                                                            }
                                                                                                            // 冗余写法目的是解决数组必填验证逻辑
                                                                                                            // 不可使用$scope.frm.xx.push
                                                                                                            var xx = angular.copy($scope.frm.${ title });
                                                                                                            xx.push($scope.frm.${ title }Opt1);
                                                                                                            $scope.frm.${ title }Opt1 = ''
                                                                                                            $scope.frm.${ title } = xx
                                                                                                        },
                                                                                                        \/\/ 枚举项的删除
                                                                                                        ${ title }Delete: function(index){
                                                                                                            // 冗余写法目的是解决数组必填验证逻辑
                                                                                                            // 不可使用$scope.frm.xx.splice
                                                                                                            var xx = angular.copy($scope.frm.${ title });
                                                                                                            xx.splice(index, 1);
                                                                                                            $scope.frm.${ title } = xx
                                                                                                        },`
            } else if(type == "弹框处理"){
                templateJ += `
                                                                                                        \/\/ 弹框
                                                                                                        ${ title }Model: function(){
                                                                                                            $uibModal.open({
                                                                                                                templateUrl: f2View,
                                                                                                                controller: f2Controller,
                                                                                                                backdrop: "true",
                                                                                                                windowClass: "sub1centercenter",
                                                                                                                size: "lg",
                                                                                                                scope:$scope.$new(),
                                                                                                                resolve: {
                                                                                                                    result: function () {
                                                                                                                        return $scope.frm.${ title } || [];
                                                                                                                    },
                                                                                                                    bwtype: function () { return 12; }
                                                                                                                }
                                                                                                            })
                                                                                                            .result.then(function (item) {
                                                                                                                $scope.frm.${ title } = item.result;
                                                                                                            }, function () {});
                                                                                                        },
                                                                                                        \/\/ 枚举项的删除
                                                                                                        ${ title }Delete: function(index){
                                                                                                            // 冗余写法目的是解决数组必填验证逻辑
                                                                                                            // 不可使用$scope.frm.xx.splice
                                                                                                            var xx = angular.copy($scope.frm.${ title });
                                                                                                            xx.splice(index, 1);
                                                                                                            $scope.frm.${ title } = xx
                                                                                                        },`
            }
        }
        templateJ = templateJ.replace(/,$/, '');
        templateJ += `
                                                                                                    }`
        for(var i = 0, l = json.formColume.length; i < l; i++) {
            var one = json.formColume[i];
            var dropName = one.dropName;
            if( !dropName ) {continue;}
            var title = one.title;
            var name = one.name;
            templateJ += `
                                                                                                    \/\/ 读取${ name }列表
                                                                                                    $API.Drop.${ dropName }('search', {
                                                                                                        \/\/ 下拉框参数
                                                                                                    }).then(function(data){
                                                                                                        $timeout(function() {
                                                                                                            $scope.frm2.${ title }List = data
                                                                                                        }, 0) }
                                                                                                    );`
        }
        templateJ += `
                                                                                                    $scope.submitFun = throttleSubmit(function(){
                                                                                                        $scope.From.submitted = true;
                                                                                                        if( $scope.From.$invalid ) {
                                                                                                            $alert.error('请检查提交的信息')
                                                                                                            return false;
                                                                                                        }
                                                                                                        var param = {};`
        for(var i = 0, l = json.formColume.length; i < l; i++) {
            var one = json.formColume[i];
            var title = one.title;
            var name = one.name;
            var type = one.type;
            if (type.indexOf('弹框处理') > -1) {
                templateJ += `
                                                                                                        param.${ title } = [];
                                                                                                        for(var i = 0, l = $scope.frm.${ title }.length; i < l; i++){
                                                                                                            param.${ title }.push( $scope.frm.${ title }[i].id )
                                                                                                        }`
            } else {
                templateJ += `
                                                                                                        param.${ title } = $scope.frm.${ title } || "";`
            }
        }
        templateJ += `
                                                                                                        return param;
                                                                                                    },function(enable, param){
                                                                                                        $API.Edit.${ json.api.submit }(param)
                                                                                                        .then(function(data) {
                                                                                                            var result = data.res_code; // 0失败 1成功
                                                                                                            enable();
                                                                                                            if( result == 1 ){
                                                                                                                $alert.success(data.res||'保存成功', function(close){
                                                                                                                    $go('app.make.maketable1')
                                                                                                                    close()
                                                                                                                 })
                                                                                                                return false;
                                                                                                            }
                                                                                                            $alert.error(data.res||'保存失败', function(close){close()})
                                                                                                        });
                                                                                                    });`
        eval(templateJ);
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        templateF += `
                                                                                                    <div class="breadcrumb">
                                                                                                        <a href="">当前位置 : 报警设置</a>
                                                                                                        <a href="">终端监控</a>
                                                                                                        <a href="">{{ frm.id?'编辑':'添加' }}</a>
                                                                                                    </div>
                                                                                                    <form class="yxf14 bigpadding" name="From">
                                                                                                        <b class="yxf14-title"> <i></i> ${ json.api.title } </b>`
        for(var i = 0, l = json.formColume.length; i < l; i++) {
            var one = json.formColume[i];
            var title = one.title;
            var type = one.type;
            var name = one.name;
            var validate = one.validate;
            var required = !!one.required;
            var bottomNote = one.bottomNote;
            templateF += `
                                                                                                        <div class="yxf14-box">
                                                                                                            <label class="yxf14-label ${ required?'must':'' }"> ${ name } </label>
                                                                                                            <div class="yxf14-control">`
            if (type.indexOf('输入框') > -1) {
                var maxlength = parseInt(one.maxlength || 300);
                var pattern = '';
                if (validate.indexOf('不可使用特殊符号') > -1) {
                    pattern = `ng-pattern="/^[0-9a-zA-Z\u4e00-\u9fa5]+$/"`;
                } else if (validate.indexOf('不可使用中文以及特殊符号') > -1) {
                    pattern = `ng-pattern="/^[0-9a-zA-Z_-]+$/"`;
                } else if (validate.indexOf('请输入0-100数字或保留两位小数') > -1) {
                    pattern = `ui-validate="{error1: 'Rule.isNumFixed012($value)', error2: '$value>=0&&$value<=100'}"`;
                } else if (validate.indexOf('请输入0-100整数') > -1) {
                    pattern = `ui-validate="{error1: 'Rule.isNum($value)', error2: '$value>=0&&$value<=100'}"`;
                } else if (validate.indexOf('请输入合理整数') > -1) {
                    pattern = `ui-validate="{error1: 'Rule.isNum($value)'}"`;
                } else {
                    continue;
                }
                templateF += `
                                                                                                                <input type="text" placeholder="请输入${ name }" style="width:200px;"
                                                                                                                    ng-model="frm.${ title }" name="${ title }"
                                                                                                                    ${ required?"required":"" } ${ pattern } ng-maxlength="${ maxlength }" maxlength="${ maxlength+1 }">
                                                                                                                <b class="note" ng-hide="(From.${ title }.$dirty || From.submitted ) && From.${ title }.$invalid">${ maxlength }位 ${ validate }</b>`
            } else if (type.indexOf('下拉框') > -1) {
                templateF += `
                                                                                                                <input type="text" placeholder="请选择${ name }" style="width:200px;"
                                                                                                                    ng-model="frm.${ title }"
                                                                                                                    select2 config="frm2.${ title }List" select2-model="frm2.${ title }"
                                                                                                                />
                                                                                                                <input type="text" style="display:none;"
                                                                                                                    ng-model="frm.${ title }" name="${ title }"
                                                                                                                    ${ required?"required":"" }
                                                                                                                 />`
            } else if (type.indexOf('文本域') > -1) {
                var maxlength = parseInt(one.maxlength || 300);
                templateF += `
                                                                                                                <textarea rows="3" placeholder="请输入${ name }" style="width:500px;"
                                                                                                                    ng-model="frm.${ title }" name="${ title }"
                                                                                                                    ${ required?"required":"" } ng-maxlength="${ maxlength }" maxlength="${ maxlength+1 }">
                                                                                                                </textarea>
                                                                                                                <b class="note"><i>{{ frm.${ title }.length || 0 }} / ${ maxlength }</i></b>`
            } else if (type.indexOf('假开关') > -1) {
                templateF += `
                                                                                                                <span class="checkbox-inline i-switch" ng-click="frm2.${ title }Change()">
                                                                                                                    <input type="checkbox" ng-checked="frm.${ title }" disabled> <i></i>
                                                                                                                </span>
                                                                                                                <b class="note"> 开发者请注意点击开关应该有判断条件状态！</b>`
            } else if (type.indexOf('开关') > -1) {
                templateF += `
                                                                                                                <label class="checkbox-inline i-switch"">
                                                                                                                    <input type="checkbox" ng-model="frm.${ title }"
                                                                                                                    ng-true-value="1" ng-false-value="0" />
                                                                                                                        <i></i>
                                                                                                                </label>`
            } else if (type.indexOf('枚举填写') > -1) {
                templateF += `
                                                                                                                <input type="text" placeholder="请输入内容" style="width:200px;"
                                                                                                                    ng-model="frm.${ title }Opt1" name="${ title }Opt1"
                                                                                                                    maxlength="5"
                                                                                                                />
                                                                                                                <button type="button" class="btn btn-danger" ng-disabled="!frm.${ title }Opt1" ng-click="frm2.${ title }Add()">添加</button>
                                                                                                            </div>
                                                                                                            <div class="yxf14-control">
                                                                                                                <input type="text" style="display:none;"
                                                                                                                    ng-model="frm.${ title }" name="${ title }"
                                                                                                                    required convert-to-string
                                                                                                                />
                                                                                                                <ul class="popupMultiBox">
                                                                                                                   <li ng-repeat="row in frm.${ title } track by $index">
                                                                                                                       <span>{{ row }}</span>
                                                                                                                       <i class="glyphicon glyphicon-remove" ng-click="frm2.${ title }Delete($index)" ></i>
                                                                                                                   </li>
                                                                                                                </ul>`
            } else if (type.indexOf('弹框处理') > -1) {
                templateF += `
                                                                                                                <button type="button" class="btn btn-danger" ng-click="frm2.${ title }Model()">选择${ name }</button>
                                                                                                            </div>
                                                                                                            <div class="yxf14-control">
                                                                                                                <input type="text" style="display:none;"
                                                                                                                    ng-model="frm.${ title }" name="${ title }"
                                                                                                                    required convert-to-string
                                                                                                                />
                                                                                                                <ul class="popupMultiBox">
                                                                                                                   <li ng-repeat="row in frm.${ title } track by $index">
                                                                                                                       <span>{{ row.name }}</span>
                                                                                                                       <i class="glyphicon glyphicon-remove" ng-click="frm2.${ title }Delete($index)" ></i>
                                                                                                                   </li>
                                                                                                                </ul>`
            } else if (type.indexOf('单选') > -1) {
                var option = '';
                try{
                    option = eval('('+ one.option +')');
                }catch(e) {
                    alert('error4545::json格式有问题');
                    console.error('json格式有问题', one.option, e);
                }
                for(var ll in option) {
                    templateF += `
                                                                                                                <label class="checkbox-inline i-checks">
                                                                                                                    <input type="radio" ng-model="frm.${ title }" convert-to-number value="${ ll }">
                                                                                                                    <i></i>${ option[ll] }
                                                                                                                </label>`
                }
            } else if (type.indexOf('复选') > -1) {
                var option = '';
                try{
                    option = eval('('+ one.option +')');
                }catch(e) {
                    alert('error4545::json格式有问题');
                    console.error('json格式有问题', one.option, e);
                }
                for(var ll in option) {
                    templateF += `
                                                                                                                <label class="checkbox-inline i-checks">
                                                                                                                    <input type="checkbox" checklist-model="frm.${ title }" checklist-value="'${ ll }'">
                                                                                                                    <i></i>${ option[ll] }
                                                                                                                </label>`
                }
            }
            if (required&&type.indexOf('枚举填写') > -1) {
                templateF += `
                                                                                                                <b class="note" style="padding: 0;" ng-show="(!From.submitted) && From.${ title }.$invalid">请配置至少一个选项</b>
                                                                                                                <b ng-show="(From.submitted) && From.${ title }.$invalid"> 请配置至少一个选项 </b>`
            } else if (required&&type.indexOf('弹框处理') > -1) {
                templateF += `
                    
                                                                                                                <b class="note" style="padding: 0;" ng-show="(!From.submitted) && From.${ title }.$invalid">请配置至少一个选项</b>
                                                                                                                <b ng-show="(From.submitted) && From.${ title }.$invalid"> 请配置至少一个选项 </b>`
            } else if (required) {
                templateF += `
                                                                                                                <b ng-show="(From.${ title }.$dirty || From.submitted ) && From.${ title }.$invalid"> {{From.${ title }.$error.required?"必填项":"${ validate }"}} </b>`
            } else {
                templateF += `
                                                                                                                <b ng-show="(From.${ title }.$dirty || From.submitted ) && From.${ title }.$invalid"> ${ validate || '' } </b>`
            }
            templateF += `
                                                                                                            </div>`
            if( bottomNote ){
                templateF += `
                                                                                                            <div class="yxf14-control">
                                                                                                                <b class="note">提示文字预留空间</b>
                                                                                                            </div>`
            }
            templateF += `
                                                                                                        </div>`


        }








        templateF += `
                                                                                                        <!-- 提交 -->
                                                                                                        <div class="yxf14-box">
                                                                                                            <div class="yxf14-control">
                                                                                                                <button type="button" class="btn btn-danger" ng-click="submitFun($event)">保存</button>
                                                                                                            </div>
                                                                                                        </div>
                                                                                                    </form>`
        var dom = $compile(templateF)($scope);
        $('#jsonMakeFrom').html(dom);
        $('#templateF').html( templateF.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n[ ]{96}/g, '\n') );
        $('#templateJ').html( templateJ.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n[ ]{96}/g, '\n') );
        $('#templateA').html( templateA.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n[ ]{96}/g, '\n') );
    });
    $scope.printFromObj = (function() {
        var str = JSON.stringify($scope.fromObj);
        console.log( str )
        var storage = window.localStorage;
        storage.setItem("makeForm13Code", str);
    });
    $scope.getFromObj = (function() {
        if( window.hahaha ){
            $scope.fromObj = json = window.hahaha;
        } else {
            var storage = window.localStorage;
            $scope.fromObj = json = eval( '('+storage.getItem("makeForm13Code")+')' );
        }
    });
}